package com.ruoyi.iot.service.impl;

import java.util.List;

import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.iot.service.IotDeviceAddProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.iot.mapper.PioltDeviceMapper;
import com.ruoyi.iot.domain.PioltDevice;
import com.ruoyi.iot.service.IPioltDeviceService;

/**
 * 观测站设备Service业务层处理
 *
 * @author rww
 * @date 2023-09-18
 */
@Service
public class PioltDeviceServiceImpl implements IPioltDeviceService
{
    @Autowired
    private PioltDeviceMapper pioltDeviceMapper;
    @Autowired
    private IotDeviceAddProcessor iotDeviceAddProcessor;

    /**
     * 查询观测站设备
     *
     * @param id 观测站设备主键
     * @return 观测站设备
     */
    @Override
    public PioltDevice selectPioltDeviceById(Long id)
    {
        return pioltDeviceMapper.selectPioltDeviceById(id);
    }

    /**
     * 查询观测站设备列表
     *
     * @param pioltDevice 观测站设备
     * @return 观测站设备
     */
    @Override
    public List<PioltDevice> selectPioltDeviceList(PioltDevice pioltDevice)
    {
        return pioltDeviceMapper.selectPioltDeviceList(pioltDevice);
    }

    /**
     * 新增观测站设备
     *
     * @param pioltDevice 观测站设备
     * @return 结果
     */
    @Override
    public int insertPioltDevice(PioltDevice pioltDevice)
    {
        pioltDevice.setId(IdUtil.getSnowflakeNextId());
        pioltDevice.setCreateTime(DateUtils.getNowDate());
        int result = pioltDeviceMapper.insertPioltDevice(pioltDevice);
        //添加任务
        iotDeviceAddProcessor.sendMsg(pioltDevice);
        return result;
    }

    /**
     * 修改观测站设备
     *
     * @param pioltDevice 观测站设备
     * @return 结果
     */
    @Override
    public int updatePioltDevice(PioltDevice pioltDevice)
    {
        pioltDevice.setUpdateTime(DateUtils.getNowDate());
        return pioltDeviceMapper.updatePioltDevice(pioltDevice);
    }

    /**
     * 批量删除观测站设备
     *
     * @param ids 需要删除的观测站设备主键
     * @return 结果
     */
    @Override
    public int deletePioltDeviceByIds(Long[] ids)
    {
        return pioltDeviceMapper.deletePioltDeviceByIds(ids);
    }

    /**
     * 删除观测站设备信息
     *
     * @param id 观测站设备主键
     * @return 结果
     */
    @Override
    public int deletePioltDeviceById(Long id)
    {
        return pioltDeviceMapper.deletePioltDeviceById(id);
    }

    @Override
    public PioltDevice selectPioltDeviceByDeviceCode(String deviceCode) {
        return pioltDeviceMapper.selectPioltDeviceByDeviceCode(deviceCode);
    }
}
